<template>
	<view>
		<u-empty :show="showEmpty" text="暂无数据" mode="list">
		</u-empty>
		<view class="topic_con u-rela" v-for="(item,index) in topic" :key="index">
			<image :src="item.image" mode="aspectFill"></image>
			<image :src="item.image" mode="aspectFill"></image>
			<view class="dis_inl_blo va_m" style="max-width: 50%;">
				<text class="u-margin-bottom-20">{{item.name}}</text>
				<text class="description">描述：{{item.description? item.description :'暂无描述'}}</text>
				<text class="time">2022-5-20</text>
			</view>
			<view class="u-abso edit_con" @click="toeditTopic(item)">编辑</view>
		</view>
		<view class="fabu" @click="show=true">
			<image src="../../static/release.png" mode="heightFix"></image>
		</view>
		<u-mask :show="show" @click="toclosemask" zIndex="2">
			<view class="warp">
				<view class="rect" @tap.stop>
					<view class="shadow_con">
						<input v-model="name" type="text" placeholder="请输入分类名称">
						<input v-model="description" type="text" placeholder="请输入分类描述">
						<view class="u-flex u-row-between">
							<view class="dis_inl_blo u-text-center" style="margin:0 40rpx;">
								<view>上传图片</view>
								<u-upload :action="action" :fileList="fileList" @on-success="successimg" @on-remove="deletePic" maxCount="1"></u-upload>
							</view>
							<view class="dis_inl_blo u-text-center" style="margin:0 40rpx;">
								<view>上传图标</view>
								<u-upload :action="action" :fileList="fileList1" @on-success="successimg1" @on-remove="deletePic1" maxCount="1"></u-upload>
							</view>
						</view>
						<button class="btn_con" @click="confirm">发布</button>
					</view>
				</view>
			</view>
		</u-mask>
		<!-- 弹框提示 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		getTopic,
		releaseTopic
	} from "@/service/indexService.js";
	export default {
		data () {
			return {
				show:false,
				showEmpty:false,
				topic:[],
				limit:10,
				page:2,
				action:'https://admin.gslhzhwy.com/api/upload/file',
				fileList:[],
				fileList1:[],
				
				
				id:0,
				name:'',
				description:'',
				image:'',
				icon:''
			}
		},
		onShow() {
			getTopic().then(this.getTopic);
		},
		onReachBottom() {
			getTopic({
				limit:this.limit,
				page:this.page
			}).then(res=>{
				// console.log(res);
				if(res.code==200){
					if(res.result.length==0){
						this.$refs.uToast.show({
							type: 'error',
							title: '没有更多啦',
							icon:false
						})
					}else{
						let list = res.result;
						list.forEach((item) => {
							this.topic.push(item);
						})
						this.page++;
					}
					
				}else {
					this.$refs.uToast.show({
						type: 'error',
						title: '没有更多啦',
						icon:false
					})
				}
			});
		},
		methods:{
			getTopic(e) {
				if (e.code == 200) {
					this.topic = e.result;
					if(e.result.length==0){
						this.showEmpty = true;
					}else{
						this.showEmpty = false;
					}
				} else {
					this.showEmpty = true;
					this.topic = [];
				}
			},
			
			successimg:function(e){
				if (e.code == 1) {
					this.image=e.data.url;
				}
			},
			// 删除图片
			deletePic(event) {
				this.image='';
			},
			successimg1:function(e){
				if (e.code == 1) {
					this.icon=e.data.url;
				}
			},
			// 删除图片
			deletePic1(event) {
				this.icon='';
			},
			toclosemask:function(){
				this.show=false;
				this.fileList=[];
				this.fileList1=[];
			},
			toeditTopic:function(item){
				uni.navigateTo({
					url:'./editActivityTopic?item='+encodeURIComponent(JSON.stringify(item))
				})
			},
			confirm:function(){
				releaseTopic({
					gid:this.id,
					name:this.name,
					description:this.description,
					image:this.image,
					icon:this.icon
				}).then(res=>{
					if(res.code==200){
						this.$refs.uToast.show({
							type: 'success',
							title: '发布成功',
							icon:false
						})
						this.show=false;
						getTopic().then(this.getTopic);
					}else{
						this.$refs.uToast.show({
							type: 'error',
							title: res.msg,
							icon:false
						})
					}
				});
				
			}
			
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #f3f5f6;
	}
	.topic_con{
		padding:20rpx 0;
		margin-bottom: 20rpx;
		background-color: #fff;
	}
	.topic_con image{
		width:130rpx;
		height:130rpx;
		margin:0 20rpx;
		vertical-align: middle;
	}
	.topic_con text{
		display: block;
	}
	.description{
		color:#666;
		font-size: 26rpx;
	}
	.time{
		color:#ffaa7f;
		font-size: 24rpx;
	}
	.edit_con{
		right:0;
		top:10rpx;
		width:80rpx;
		height:50rpx;
		font-size: 24rpx;
		text-align: center;
		line-height: 50rpx;
		color:#fff;
		background-color: #aaaa7f;
		border-top-left-radius: 25rpx;
		border-bottom-left-radius: 25rpx;
	}
	.fabu{
		position: fixed;
		bottom:150rpx;
		right:30rpx;
		width:100rpx;
		height:100rpx;
		// text-align: center;
		border-radius: 50%;
	}
	.fabu image{
		width:100rpx;
		height:100rpx;
	}
	
	.warp {
		display: flex;
		align-items: flex-end;
		justify-content: center;
		height: 100%;
	}
	
	.rect {
		width: 100%;
		height: 400px;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		background-color: #fff;
	}
	.shadow_con{
		padding:80rpx 20rpx;
	}
	.shadow_con input{
		width:93%;
		height:70rpx;
		font-size: 28rpx;
		padding:0 20rpx;
		margin-bottom:30rpx;
		border-radius: 10rpx;
		border:1rpx solid #ccc;
		background-color: #fafafa;
	}
	.btn_con{
		height:70rpx;
		line-height: 70rpx;
		font-size: 30rpx;
		border-radius: 35rpx;
		background-image: url('https://resourse.cnlhjt.com/upload/20220825/d1aa35c1d129137d9b12c8f34e59c5bc.png');
		background-size: 100% 70rpx;
		color:#fff;
		margin-top:80rpx;
	}
</style>
